

#import "HitPath.h"
#import "PSWUPath.h"

@implementation HitPath

static float officialHitWidth;

//************************************************************************
// creating and destroying

+ initialize
{
   if(self == [HitPath class])
         officialHitWidth = 4.0;
   return self;
}
 
- init
{  
   [super initCountParams:8 countOps:4];
   [self resetFill];
        [self moveto:0 :0];
        [self rlineto:0 :0];
        [self rlineto:0 :0];
        [self rlineto:0 :0];
   [self closepath];
   hitWidth = officialHitWidth;
   return self;
}
   
//************************************************************************
// misc

- movePathToPoint:(const NXPoint *)p
{
   bbox[0] = floor(p->x - hitWidth / 2);
   bbox[1] = floor(p->y - hitWidth / 2);
   bbox[2] = ceil(p->x + hitWidth / 2);
   bbox[3] = ceil(p->y + hitWidth / 2);
   params[0] = p->x - hitWidth / 2;
   params[1] = p->y - hitWidth / 2;
   params[3] = hitWidth;
   params[4] = hitWidth;
   params[7] = - hitWidth;
   return self;
}

- (BOOL)hitPathStroke:(UPath *)aPath
{
   int hit;
   
   PSWHitStroke(bboxParams,sizeParams + 4,bboxOps,sizeOps + 2,
   aPath->bboxParams,aPath->sizeParams + 4,aPath->bboxOps,aPath->sizeOps + 2,&hit);
   return (BOOL)hit;
}

- (BOOL)hitPathFill:(UPath *)aPath
{
   int hit;

   PSWHitFill(bboxParams,sizeParams + 4,bboxOps,sizeOps + 2,
   aPath->bboxParams,aPath->sizeParams + 4,aPath->bboxOps,aPath->sizeOps + 2,&hit);
   return (BOOL)hit;
}

- awake
{
   [super awake];
   hitWidth = officialHitWidth;
   return self;
}

- scaleHitWidthTo:(float)aScale
{
   NXPoint aPoint;

   aPoint.x = params[0] + hitWidth / 2;
   aPoint.y = params[1] + hitWidth / 2;
   hitWidth = officialHitWidth * (1.0 / aScale);
   [self movePathToPoint:&aPoint];
   return self;
}
             
@end
